import request from '../index';

export default {
  // 获取商品列表
  getList: (params) => request.get('/goods', params),
  
  // 获取商品详情
  getDetail: (id) => request.get(`/goods/${id}`),
  
  // 获取商品分类
  getCategories: () => request.get('/goods/categories'),
  
  // 获取我的商品
  getMyGoods: (params) => request.get('/goods/my', params),
  
  // 发布商品
  publish: (data) => request.post('/goods', data),
  
  // 更新商品
  update: (id, data) => request.put(`/goods/${id}`, data),
  
  // 删除商品
  delete: (id) => request.del(`/goods/${id}`),
  
  // 上下架商品
  toggleStatus: (id, data) => request.put(`/goods/${id}/status`, data),
  
  // 上传商品图片
  uploadImages: (filePaths) => {
    return Promise.all(
      filePaths.map(filePath => request.upload('/goods/upload-image', filePath))
    );
  },
  
  // 获取收藏商品
  getFavorites: (params) => request.get('/goods/favorites', params),
  
  // 收藏商品
  favorite: (id) => request.post(`/goods/${id}/favorite`),
  
  // 取消收藏
  unfavorite: (id) => request.del(`/goods/${id}/favorite`),
  
  // 获取热销商品
  getHotGoods: (params) => request.get('/goods/hot', params),
  
  // 获取推荐商品
  getRecommendGoods: (params) => request.get('/goods/recommend', params),
  
  // 搜索商品
  search: (params) => request.get('/goods/search', params),
  
  // 获取商品评价
  getReviews: (id, params) => request.get(`/goods/${id}/reviews`, params),
  
  // 商品评价
  review: (id, data) => request.post(`/goods/${id}/review`, data)
};